package puc.redes.tarea3.server;

import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;

public class QueryRemoteSparql {
	public static void main(String args[]) {

		ResultSet rs = null;
		long startTime = 0;
		startTime = System.currentTimeMillis();
		System.out.println("Start Time: " + startTime);
		String queryString = "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> "
                + "PREFIX p: <http://dbpedia.org/property/> "
                + "SELECT ?player ?club "
                + "WHERE{"
                + "   ?player p:cityofbirth <http://dbpedia.org/resource/Dublin>. } "
                + "       ";
		final QueryExecution qexec = QueryExecutionFactory.sparqlService(
				"http://dbpedia.org/sparql", queryString);
		try {
			rs = qexec.execSelect();
			ResultSetFormatter.outputAsRDF("RDF/XML", rs);
			int resultNumer = 0;
//			for (; rs.hasNext();) {
//				 QuerySolution qs = rs.next();
//	                
//			}
			System.out.println("Number of Results: " + resultNumer);
		} finally {
			qexec.close();
			long totalTime1 = System.currentTimeMillis() - startTime;
			System.out.println("total time: " + totalTime1);
		}
	}
}
